<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="LINKED_CONTENT_FIELD_VALUES_COLLECTION_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="LINKED_MENU_ITEMS_COLLECTION_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="LINKED_CONTENT_FIELD_VALUES_AND_MENU_ITEMS_INFOS_COLLECTION_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="LINKED_OBJECTS_REDIRECT_URL_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="LINKED_OBJECTS_INFO_CONTAINER_KEY" />
<atleap:constants className="org.apache.struts.taglib.html.Constants" var="TOKEN_KEY" />
<atleap:constants className="org.apache.struts.Globals" var="TRANSACTION_TOKEN_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.struts.ContentTilesRequestProcessor" var="PROCESSED_URL" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="GRID_PAGE_SIZE" />
<atleap:globalProperty name="${pageScope.GRID_PAGE_SIZE}" defaultValue="10" type="integer" var="pageSize" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.LinkedObjectsInfoContainer" var="TYPE_PAGE" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.LinkedObjectsInfoContainer" var="TYPE_RESOURCE" />

<c:set var="infoContainer" value="${sessionScope[pageScope.LINKED_OBJECTS_INFO_CONTAINER_KEY]}" />

<atleap:isUserInRole roles="core-contentFieldValue-createOrUpdate" var="canUpdateCFV" />
<atleap:isUserInRole roles="core-contentFieldValue-view" var="canViewCFV" />
<atleap:isUserInRole roles="core-menuItem-update" var="canUpdateMI" />
<atleap:isUserInRole roles="core-menuItem-view" var="canViewMI" />

<c:set var="infoCellsCFV" value="3" />
<c:set var="constantButtonCellsCFV" value="0" />
<c:set var="additionalCellsCFV" value="0" />
<c:if test="${canUpdateCFV}">
	<c:set var="additionalCellsCFV" value="${additionalCellsCFV+1}" />
</c:if>
<c:if test="${canViewCFV}">
	<c:set var="additionalCellsCFV" value="${additionalCellsCFV+1}" />
</c:if>
<c:set var="infoCellsMI" value="2" />
<c:set var="constantButtonCellsMI" value="0" />
<c:set var="additionalCellsMI" value="0" />
<c:if test="${canUpdateMI}">
	<c:set var="additionalCellsMI" value="${additionalCellsMI+1}" />
</c:if>
<c:if test="${canViewMI}">
	<c:set var="additionalCellsMI" value="${additionalCellsMI+1}" />
</c:if>

<atleap:content identifier="information" ignore="true" />
<atleap:messages />

<atleap:iterator items="${requestScope[pageScope.LINKED_CONTENT_FIELD_VALUES_AND_MENU_ITEMS_INFOS_COLLECTION_KEY]}" var="info">
    <h3>
        <atleap:message key="core.linkedObjects.contentFieldValueList" /> (${info.objectInfo})
    </h3>
    <atleap:content identifier="information" ignore="true" />
    <atleap:grid name="linkedContentFieldValuesGrid" pageSize="${pageSize}">
        <table border="0" cellpadding="0" cellspacing="0" class="grid">
            <thead>
                <tr nowrap="nowrap">
                    <th nowrap="nowrap">
                        <atleap:message key="core.linkedObjects.contentFieldValue.fieldIdentifier" />
                    </th>
                    <th nowrap="nowrap">
                        <atleap:message key="core.linkedObjects.contentFieldValue.fieldOwner" />
                    </th>
                    <th nowrap="nowrap">
                        <atleap:message key="core.linkedObjects.contentFieldValue.language" />
                    </th>
                    <th colspan="${constantButtonCellsCFV + additionalCellsCFV}">
                        <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/spacer.gif" />" border="0"  />
                    </th>
                 </tr>
            </thead>
            <tbody>
                <atleap:contextMenu var="CFVMenuId">
                    <atleap:rowsIterator collection="${info.cfvInfos}" var="cfvInfo" oddClass="oddRow" evenClass="evenRow">
                        <atleap:itemSet>
                            <atleap:rewriteUrl action="core/contentFieldValue/view?contentFieldId=${cfvInfo.fieldId}&contentFieldValueId=${cfvInfo.fieldValueId}&locale=${cfvInfo.language}" var="defaultUrl">
                                <atleap:param name="redirectUrl" value="${requestScope[pageScope.PROCESSED_URL]}" />
                            </atleap:rewriteUrl>
                            <c:set var="onTrClickCode" value="" />
                            <c:set var="tdClass" value="defaultCursorCell" />
                            <c:if test="${canViewCFV}">
                                <c:set var="onTrClickCode" value="dispatchGridTrClick(event, this, &#039;${defaultUrl}&#039;);" />
                                <c:set var="tdClass" value="pointerCursorCell" />
                            </c:if>
                            <tr class="${rowClass}" oncontextmenu="return showContextMenu(${CFVMenuId}, event, ${indexId});" onclick="${onTrClickCode}">
                                <td class="${tdClass}"><c:out value="${cfvInfo.fieldIdentifier}" escapeXml="true" /></td>
                                <td class="${tdClass}">${cfvInfo.fieldOwnerInfo}</td>
                                <td class="${tdClass}"><c:out value="${cfvInfo.language}" escapeXml="true" /></td>
                                <atleap:item includeInContextMenu="${canUpdateCFV}" includeInPage="${canUpdateCFV}">
                                    <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                                        <atleap:itemEnabled>
                                            <atleap:message key="core.commons.buttons.callUpdate" var="callUpdateMsg" />
                                            <atleap:itemLink action="core/contentFieldValue/callCreateOrUpdate?contentFieldId=${cfvInfo.fieldId}&contentFieldValueId=${cfvInfo.fieldValueId}&locale=${cfvInfo.language}" title="${callUpdateMsg}">
                                                <atleap:param name="redirectUrl" value="${requestScope[pageScope.PROCESSED_URL]}" />
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/edit.gif" />" border="0" title="${callUpdateMsg}" alt="${callUpdateMsg}" align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${callUpdateMsg}
                                                </atleap:itemLabel>
                                            </atleap:itemLink>
                                        </atleap:itemEnabled>
                                    </td>
                                </atleap:item>
                                <atleap:item includeInContextMenu="${canViewCFV}" includeInPage="${canViewCFV}">
                                    <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                                        <atleap:itemEnabled>
                                            <atleap:message key="core.commons.buttons.view" var="viewMsg"/>
                                            <atleap:itemLink action="core/contentFieldValue/view?contentFieldId=${cfvInfo.fieldId}&contentFieldValueId=${cfvInfo.fieldValueId}&locale=${cfvInfo.language}" title="${viewMsg}">
                                                <atleap:param name="redirectUrl" value="${requestScope[pageScope.PROCESSED_URL]}" />
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/view.gif" />" border="0" title="${viewMsg}" alt="${viewMsg}" align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${viewMsg}
                                                </atleap:itemLabel>
                                            </atleap:itemLink>
                                        </atleap:itemEnabled>
                                    </td>
                                </atleap:item>
                            </tr>
                        </atleap:itemSet>
                    </atleap:rowsIterator>
                </atleap:contextMenu>
                <atleap:noRows>
                    <tr>
                        <td class="tfoot" colspan="${infoCellsCFV + constantButtonCellsCFV + additionalCellsCFV}" align="center">
                            <em><atleap:message key="core.commons.nothingToShow"/></em>
                        </td>
                    </tr>
                </atleap:noRows>
            </tbody>
            <tfoot>
                <tr>
                    <atleap:pager pageCount="10">
                        <td colspan="${infoCellsCFV + constantButtonCellsCFV + additionalCellsCFV}" align="center">
                            <atleap:message key="core.grid.pager.title" />&nbsp;
                            <atleap:firstPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/first.gif" />" border="0" alt="<atleap:message key="core.grid.pager.first"/>" title="<atleap:message key="core.grid.pager.first"/>" /></atleap:firstPage>
                            <atleap:prevPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/prev.gif" />" border="0" alt="<atleap:message key="core.grid.pager.prev"/>" title="<atleap:message key="core.grid.pager.prev"/>" /></atleap:prevPage>
                            <atleap:pagesIterator>
                                <atleap:page>${pageNumber}&nbsp;</atleap:page>
                                <atleap:currentPage><b>${pageNumber}</b>&nbsp;</atleap:currentPage>
                            </atleap:pagesIterator>
                            <atleap:nextPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/next.gif" />" border="0" alt="<atleap:message key="core.grid.pager.next"/>" title="<atleap:message key="core.grid.pager.next"/>" /></atleap:nextPage>
                            <atleap:lastPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/last.gif" />" border="0" alt="<atleap:message key="core.grid.pager.last"/>" title="<atleap:message key="core.grid.pager.last"/>" /></atleap:lastPage>
                        </td>
                    </atleap:pager>
                </tr>
            </tfoot>
        </table>
    </atleap:grid>
    <h3>
        <atleap:message key="core.linkedObjects.menuItemList" /> (${info.objectInfo})
    </h3>
    <atleap:grid name="linkedMenuItemsGrid" pageSize="${pageSize}">
        <table border="0" cellpadding="0" cellspacing="0" class="grid">
            <thead>
                <tr nowrap="nowrap">
                    <th nowrap="nowrap">
                        <atleap:message key="core.linkedObjects.menuItem.title" />
                    </th>
                    <th nowrap="nowrap">
                        <atleap:message key="core.linkedObjects.menuItem.owner" />
                    </th>
                    <th colspan="${constantButtonCellsMI + additionalCellsMI}">
                        <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/spacer.gif" />" border="0"  />
                    </th>
                 </tr>
            </thead>
            <tbody>
                <atleap:contextMenu var="MIMenuId">
                    <atleap:rowsIterator collection="${info.menuItemInfos}" var="menuItemInfo" oddClass="oddRow" evenClass="evenRow">
                        <atleap:itemSet>
                            <atleap:rewriteUrl action="core/menuItem/view?id=${menuItemInfo.menuItemId}&ownerId=${menuItemInfo.ownerId}" var="defaultUrl">
                                <atleap:param name="redirectUrl" value="${requestScope[pageScope.PROCESSED_URL]}" />
                            </atleap:rewriteUrl>
                            <c:set var="rowIsPressable" value="${menuItemInfo.dynamic && canViewMI}" />
                            <c:set var="onTrClickCode" value="" />
                            <c:if test="${rowIsPressable}" >
                                <c:set var="onTrClickCode" value="dispatchGridTrClick(event, this, &#039;${defaultUrl}&#039;);" />
                            </c:if>
                            <tr class="${rowClass}" oncontextmenu="return showContextMenu(${MIMenuId}, event, ${indexId});" onclick="${onTrClickCode}">
                                <c:choose>
                                    <c:when test="${rowIsPressable}">
                                        <td>
                                            <atleap:message key="${menuItemInfo.title}" var="titleMsg" ignore="true" />
                                            <c:if test="${empty titleMsg}">
                                                <c:set var="titleMsg" value="${menuItemInfo.title}" />
                                            </c:if>
                                            <c:out value="${titleMsg}" escapeXml="true" />
                                        </td>
                                        <td>${menuItemInfo.ownerInfo}</td>
                                    </c:when>
                                    <c:otherwise>
                                        <td class="defaultCursorCell">
                                            <atleap:message key="${menuItemInfo.title}" var="titleMsg" ignore="true" />
                                            <c:if test="${empty titleMsg}">
                                                <c:set var="titleMsg" value="${menuItemInfo.title}" />
                                            </c:if>
                                            <c:out value="${titleMsg}" escapeXml="true" />
                                        </td>
                                        <td class="defaultCursorCell">${menuItemInfo.ownerInfo}</td>
                                    </c:otherwise>
                                </c:choose>
                                <atleap:item enabled="${menuItemInfo.dynamic}" includeInContextMenu="${canUpdateMI}" includeInPage="${canUpdateMI}">
                                    <atleap:message key="core.commons.buttons.callUpdate" var="callUpdateMsg" />
                                    <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                                        <atleap:itemEnabled>
                                            <atleap:itemLink action="core/menuItem/callUpdate?id=${menuItemInfo.menuItemId}&ownerId=${menuItemInfo.ownerId}" title="${callUpdateMsg}">
                                                <atleap:param name="redirectUrl" value="${requestScope[pageScope.PROCESSED_URL]}" />
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/edit.gif" />" border="0" alt="${callUpdateMsg}" title="${callUpdateMsg}" align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${callUpdateMsg}
                                                </atleap:itemLabel>
                                            </atleap:itemLink>
                                        </atleap:itemEnabled>
                                        <atleap:itemDisabled>
                                            <atleap:message key="core.menuItem.form.editDisabled" var="editDisabledMsg" />
                                            <atleap:itemLink title="${editDisabledMsg}">
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/editDisabled.gif" />" border="0" alt="${editDisabledMsg}" title="${editDisabledMsg}"  />
                                                <atleap:itemLabel>
                                                    ${callUpdateMsg}
                                                </atleap:itemLabel>
                                            </atleap:itemLink>
                                        </atleap:itemDisabled>
                                    </td>
                                </atleap:item>
                                <atleap:item enabled="${menuItemInfo.dynamic}" includeInContextMenu="${canViewMI}" includeInPage="${canViewMI}">
                                    <atleap:message key="core.commons.buttons.view" var="viewMsg"/>
                                    <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                                        <atleap:itemEnabled>
                                            <atleap:itemLink action="core/menuItem/view?id=${menuItemInfo.menuItemId}&ownerId=${menuItemInfo.ownerId}" title="${viewMsg}">
                                                <atleap:param name="redirectUrl" value="${requestScope[pageScope.PROCESSED_URL]}" />
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/view.gif" />" border="0" title="${viewMsg}" alt="${viewMsg}" align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${viewMsg}
                                                </atleap:itemLabel>
                                            </atleap:itemLink>
                                        </atleap:itemEnabled>
                                        <atleap:itemDisabled>
                                            <atleap:message key="core.menuItem.form.viewDisabled" var="viewDisabledMsg" />
                                            <atleap:itemLink title="${viewDisabledMsg}">
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/viewDisabled.gif" />" border="0" alt="${viewDisabledMsg}" title="${viewDisabledMsg}"  />
                                                <atleap:itemLabel>
                                                    ${viewMsg}
                                                </atleap:itemLabel>
                                            </atleap:itemLink>
                                        </atleap:itemDisabled>
                                    </td>
                                </atleap:item>
                            </tr>
                        </atleap:itemSet>
                    </atleap:rowsIterator>
                </atleap:contextMenu>
                <atleap:noRows>
                    <tr>
                        <td class="tfoot" colspan="${infoCellsMI + constantButtonCellsMI + additionalCellsMI}" align="center">
                            <em><atleap:message key="core.commons.nothingToShow"/></em>
                        </td>
                    </tr>
                </atleap:noRows>
            </tbody>
            <tfoot>
                <tr>
                    <atleap:pager pageCount="10">
                        <td colspan="${infoCellsMI + constantButtonCellsMI + additionalCellsMI}" align="center">
                            <atleap:message key="core.grid.pager.title" />&nbsp;
                            <atleap:firstPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/first.gif" />" border="0" alt="<atleap:message key="core.grid.pager.first"/>" title="<atleap:message key="core.grid.pager.first"/>" /></atleap:firstPage>
                            <atleap:prevPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/prev.gif" />" border="0" alt="<atleap:message key="core.grid.pager.prev"/>" title="<atleap:message key="core.grid.pager.prev"/>" /></atleap:prevPage>
                            <atleap:pagesIterator>
                                <atleap:page>${pageNumber}&nbsp;</atleap:page>
                                <atleap:currentPage><b>${pageNumber}</b>&nbsp;</atleap:currentPage>
                            </atleap:pagesIterator>
                            <atleap:nextPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/next.gif" />" border="0" alt="<atleap:message key="core.grid.pager.next"/>" title="<atleap:message key="core.grid.pager.next"/>" /></atleap:nextPage>
                            <atleap:lastPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/last.gif" />" border="0" alt="<atleap:message key="core.grid.pager.last"/>" title="<atleap:message key="core.grid.pager.last"/>" /></atleap:lastPage>
                        </td>
                    </atleap:pager>
                </tr>
            </tfoot>
        </table>
    </atleap:grid>
</atleap:iterator>

<table border="0" cellpadding="0" cellspacing="5">
	<tr>
		<c:if test="${!empty infoContainer.deleteAction}">
			<td>
				<atleap:form action="${infoContainer.deleteAction}" method="GET" validateOnSubmit="false" onsubmit="disableButtonsInAllForms(true);return true;">
					<html:hidden property="force" value="true" />
                    <c:if test="${infoContainer.objectId != null}">
                        <html:hidden property="id" value="${infoContainer.objectId}" />
                    </c:if>
                    <c:if test="${infoContainer.path != null}">
                        <html:hidden property="path" value="${infoContainer.path}" />
                    </c:if>
                    <atleap:submit styleClass="button">
						<atleap:message key="core.commons.buttons.delete" />
					</atleap:submit>
				</atleap:form>
			</td>
		</c:if>
		<c:if test="${!empty infoContainer.updateAction}">
			<td>
				<atleap:form action="${infoContainer.updateAction}" method="GET" validateOnSubmit="false" onsubmit="disableButtonsInAllForms(true);return true;">
					<html:hidden property="force" value="true" />
                    <c:if test="${infoContainer.newUri != null}">
                        <html:hidden property="uri" value="${infoContainer.newUri}" />
                    </c:if>
                    <c:if test="${infoContainer.contentLocaleId != null}">
                        <html:hidden property="contentLocaleId" value="${infoContainer.contentLocaleId}" />
                    </c:if>
                    <c:if test="${infoContainer.charset != null}">
                        <html:hidden property="charset" value="${infoContainer.charset}" />
                    </c:if>
                    <c:if test="${infoContainer.width != null}">
                        <html:hidden property="width" value="${infoContainer.width}" />
                    </c:if>
                    <c:if test="${infoContainer.height != null}">
                        <html:hidden property="height" value="${infoContainer.height}" />
                    </c:if>
                    <c:if test="${infoContainer.publicationDate != null}">
                        <html:hidden property="publicationDate" value="${infoContainer.publicationDate}" />
                    </c:if>
                    <c:if test="${infoContainer.expirationDate != null}">
                        <html:hidden property="expirationDate" value="${infoContainer.expirationDate}" />
                    </c:if>
                    <c:if test="${infoContainer.objectId != null}">
                        <html:hidden property="id" value="${infoContainer.objectId}" />
                    </c:if>
                    <c:if test="${infoContainer.path != null}">
                        <html:hidden property="path" value="${infoContainer.path}" />
                    </c:if>
                    <c:if test="${infoContainer.newPath != null}">
                        <html:hidden property="newPath" value="${infoContainer.newPath}" />
                    </c:if>
                    <atleap:submit styleClass="button">
						<atleap:message key="core.commons.buttons.update" />
					</atleap:submit>
				</atleap:form>
			</td>
		</c:if>
        <td>
            <c:if test="${requestScope[pageScope.LINKED_OBJECTS_REDIRECT_URL_KEY] != null}">
                <form method="POST" action="${requestScope[pageScope.LINKED_OBJECTS_REDIRECT_URL_KEY]}" onsubmit="disableButtonsInAllForms(true);return true;">
                    <input type="submit" class="button" value="<atleap:message key="core.commons.buttons.cancel" />" />
                    <c:if test="${infoContainer.objectId != null}" >
                        <html:hidden property="id" value="${infoContainer.objectId}" />
                    </c:if>
                </form>
            </c:if>
        </td>
    </tr>
</table>
